//
//  Bonus.m
//  SDDataTest
//
//  Created by sodao on 12-9-20.
//  Copyright (c) 2012年 sodao. All rights reserved.
//

#import "Bonus.h"

@implementation Bonus
@synthesize giftID;
@synthesize giftName;
@synthesize picURL;
@synthesize count;
@synthesize needMC;
@synthesize needSC;
@synthesize exChangeDate;
@synthesize exchangeType;
@synthesize exchangeState;


- (void)encodeWithCoder:(NSCoder *)aCoder{
    [super encodeWithCoder:aCoder];
    [aCoder encodeObject:self.giftID forKey:kEncodeBonus_giftID];
    [aCoder encodeObject:self.giftName forKey:kEncodeBonus_giftName];
    [aCoder encodeObject:self.picURL forKey:kEncodeBonus_picURL];
    [aCoder encodeInt:self.count forKey:kEncodeBonus_count];
    [aCoder encodeInt:self.needMC forKey:kEncodebonus_needMC];
    [aCoder encodeInt:self.needSC forKey:kEncodebonus_needSC];
    [aCoder encodeObject:self.exChangeDate forKey:kEncodeBonus_exChangeDate];
    [aCoder encodeInt:self.exchangeType forKey:kEncodebonus_exChangeType];
    [aCoder encodeInt:self.exchangeState forKey:kEncodebonus_exChangeState];
}
- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super initWithCoder:decoder]) {
        self.giftID = [decoder decodeObjectForKey:kEncodeBonus_giftID];
        self.giftName = [decoder decodeObjectForKey:kEncodeBonus_giftName];
        self.picURL = [decoder decodeObjectForKey:kEncodeBonus_picURL];
        self.count = [decoder decodeIntForKey:kEncodeBonus_count];
        self.needMC = [decoder decodeIntForKey:kEncodebonus_needMC];
        self.needSC = [decoder decodeIntForKey:kEncodebonus_needSC];
        self.exChangeDate = [decoder decodeObjectForKey:kEncodeBonus_exChangeDate];
        self.exchangeState = [decoder decodeIntForKey:kEncodebonus_exChangeState];
        self.exchangeType = [decoder decodeIntForKey:kEncodebonus_exChangeType];
    }
    return self;
}
-(id)initWithDictionary:(NSDictionary*)dictionary{
    self = [super initWithDictionary:dictionary];
    if (self) {
        self.giftID = [self getFeedIDByObject:[dictionary objectForKey:@"Gift_id"]];
        
        if ([dictionary objectForKey:kEncodebonus_needMC]==nil) {
            self.giftName = [dictionary objectForKey:kEncodebonus_exChangeName];
            self.picURL = [dictionary objectForKey:kEncodebonus_exChangePicURL];
            self.needMC = [[dictionary objectForKey:kEncodebonus_exChangeMC] intValue];
            self.needSC = [[dictionary objectForKey:kEncodebonus_exChangeSC] intValue];
            self.exchangeState = [[dictionary objectForKey:kEncodebonus_exChangeState] intValue];
            self.exChangeDate = [self getServerUTC:[[dictionary objectForKey:kEncodeBonus_exChangeDate] longLongValue]];
        }else{
            self.giftName = [dictionary objectForKey:kEncodeBonus_giftName];
            self.picURL = [dictionary objectForKey:kEncodebonus_exChangePicURL];
            self.needMC = [[dictionary objectForKey:kEncodebonus_needMC] intValue];
            self.needSC = [[dictionary objectForKey:kEncodebonus_needSC] intValue];
            self.count = [[dictionary objectForKey:kEncodebonus_exChangeState] intValue];
            self.exchangeType = -1;
            self.exChangeDate = nil;
        }
        
    }
    return self;
}
-(void)dealloc{
    [super dealloc];
    if(self.giftID)[self.giftID release];
    if(self.giftName)[self.giftName release];
    if(self.picURL)[self.picURL release];
    if(self.exChangeDate)[self.exChangeDate release];
}



@end
